import {ElLoading} from 'element-plus';
import {ILoadingInstance} from 'element-plus/es/el-loading/src/loading.type';
import {nextTick} from 'vue';

class PageLoading {
  private loadingTarget!: ILoadingInstance;

  public openPageLoading(): void {
    this.loadingTarget = ElLoading.service({
      fullscreen: true,
      lock: true,
      text: '正在加载中',
      background: 'rgba(0, 0, 0, 0.7)',
    });
  }

  public closePageLoading(): void {
    if (this.loadingTarget) {
      this.loadingTarget.close();
    } else {
      ElLoading.service({fullscreen: true, lock: true, text: '正在加载中', background: 'rgba(0, 0, 0, 0.7)'}).close();
    }
  }
}

export let pageLoading = new PageLoading();

export class Loading {
  public value!: boolean;
}


